//
// Created by User on 24-10-7.
//
#include "general_encoder.h"
#include "general_demuxer.h"
#include <gtest/gtest.h>
#include <glog/logging.h>
#include <libavcodec/packet.h>

#include "audio_config.hpp"
#include "audio_decoder.h"
#include "video_config.hpp"
#include "video_decoder.h"

TEST(encoder_test, encoder_init)
{
    demuxer::general_demuxer demuxer(VIDEO_PATH);
    utils::video_config video_config1 = utils::video_config::cbr_config("x264", utils::video_config::profile::MAIN,
                                                                        1920, 1080, 60, 2000000);
    utils::audio_config audio_config1 = utils::audio_config::config(128000, 48000);
    decoder::general_decoder decoder1(*demuxer.get_streams()[0]);
    decoder::general_decoder decoder2(*demuxer.get_streams()[1]);
    decoder::video_decoder video_decoder1(decoder1);
    decoder::audio_decoder audio_decoder1(decoder2);
    encoder::general_encoder video_encoder(video_config1, video_decoder1);
    encoder::general_encoder audio_encoder(audio_config1, audio_decoder1);
    LOG(INFO) << "done";
}

TEST(encoder_test, encoder_get_packet)
{
    demuxer::general_demuxer demuxer(VIDEO_PATH);
    utils::video_config video_config1 = utils::video_config::cbr_config("x264", utils::video_config::profile::MAIN,
                                                                        1920, 1080, 60, 2000000);
    utils::audio_config audio_config1 = utils::audio_config::config(128000, 48000);
    decoder::general_decoder decoder1(*demuxer.get_streams()[0]);
    decoder::general_decoder decoder2(*demuxer.get_streams()[1]);
    decoder::video_decoder video_decoder1(decoder1);
    decoder::audio_decoder audio_decoder1(decoder2);
    encoder::general_encoder video_encoder(video_config1, video_decoder1);
    encoder::general_encoder audio_encoder(audio_config1, audio_decoder1);
    for (int i = 1;; ++i)
    {
        auto video_pkt = video_encoder.get_packet();
        if (!video_pkt)
        {
            break;
        }
        LOG(INFO) << "video pkt : " << i << "\t pts : " << video_pkt.get_packet()->pts
            << "\t dts : " << video_pkt.get_packet()->dts;
    }

    for (int i = 1;; ++i)
    {
        auto audio_pkt = audio_encoder.get_packet();
        if (!audio_pkt)
        {
            break;
        }
        LOG(INFO) << "audio pkt : " << i << "\t pts : " << audio_pkt.get_packet()->pts
            << "\t dts : " << audio_pkt.get_packet()->dts;
    }
}
